package net.lzzy.practices.entities;


import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.net.PasswordAuthentication;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author m
 */
@Entity //指定为实体类 Entity注解 都会被 practitces 映射到数据库
@Getter
@Setter
public class User extends  BaseEntity {

    @Transient //将不会映射到数据库
    public static final int TYPE_BANNED = -1;
    @Transient
    public  static  final  int TYPE_ADMIN=0;
    @Transient
    public  static  final  int TYPE_TEACHER=1;
    @Transient
    public  static  final  int TYPE_STUDENT=2;

//    PasswordAuthentication passwordAuthentication= new


   private   String nickName;
   private  String userName;

   private String email;
   private String phone;

   private String password;

   private String avatar;

   private  int type;

   private  String salt;

   private boolean applyTeacher;

   @Temporal(TemporalType.TIMESTAMP) //最高精度时间
   private Date createTime;

   @Temporal(TemporalType.TIMESTAMP)
   private  Date updateTime;
//   教师是一个 ，课程可以上多个
    //
    @OneToMany(mappedBy = "teacher") //一对多 指向课程类(Course) 的 teacher的字段
   private List<Course> courses = new ArrayList<>();
    @ManyToMany(mappedBy = "students") //多对多 学生可以查看课程
    //学生类
    private  List<Course> enrolledCourses= new ArrayList<>();
    @OneToMany(mappedBy = "student")
    private List<Result> results= new ArrayList<>();
    @OneToMany(mappedBy = "student")
    private  List<Applicant> applicants= new ArrayList<>();
    public  User(){
        createTime=new Date();
        updateTime=new Date();

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        User user = (User) o;
        return id.equals(user.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
